package com.cdream.basic.algorithm.leetcode.findElement;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cdream
 * @date 5/22/21
 */
public class Question205 {
    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> map = new HashMap<>();

        for (int i = 0; i < s.length(); i++) {
            Character c = map.get(s.charAt(i));
            if (c == null) {
                if (map.containsValue(t.charAt(i))){
                    return false;
                }
                map.put(s.charAt(i), t.charAt(i));
            } else {
                if (c != t.charAt(i)) {
                    return false;
                }

            }
        }
        return true;

    }

    public static void main(String[] args) {
        System.out.println(new Question205().isIsomorphic("badc", "baba"));
    }
}
